﻿#include "register.h"
#include "ui_register.h"

Register::Register(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Register)
{
    ui->setupUi(this);
    m_ptrSql = Sqlite::getIntance();
    //设置样式表
//    ui->le_name->setStyleSheet("border-top:0px solid;"
//                               "border-left:0px solid;"
//                               "border-right:0px solid;"
//                               "border-bottom:2px solid;");/*只显示底部边框、实线*/
//    ui->le_pswd->setStyleSheet("border-top:0px solid;"
//                               "border-left:0px solid;"
//                               "border-right:0px solid;"
//                               "border-bottom:2px solid;");/*只显示底部边框、实线*/
}

Register::~Register()
{
    delete ui;
}

void Register::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.setOpacity(0.7);  //透明度
    QPixmap pixmap = QPixmap(":/pic/widget").scaled(this->size());// 加载背景图片
    painter.drawPixmap(this->rect(), pixmap);// 绘制背景图片
}

void Register::on_pb_reg_clicked()
{
  User info;
  info.name  = ui->le_name->text();
  info.pswd = ui->le_pswd->text();
   if(info.name.isEmpty() ||  info.pswd.isEmpty()){
       QMessageBox::information(nullptr, "提示","账号密码不能为空！");
       return;
   }
   if(m_ptrSql->isExist(info.name) == true){
        QMessageBox::information(nullptr,"提示" ,"该账户已经被注册过，请重新输入!");
        return;
   }
    m_ptrSql->addUser(info);
    QMessageBox::information(nullptr, "提示" , "成功注册！");
    ui->le_name->clear();
    ui->le_pswd->clear();
}

void Register::on_pb_reback_clicked()
{
   emit reaback();
   this->hide();
}
